package com.wwwarehouse.carddesk.adapter.teamadapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;

import com.wwwarehouse.carddesk.R;
import com.wwwarehouse.carddesk.bean.teambean.DelayTaskBean;
import com.wwwarehouse.common.tools.ConvertUtils;
import com.wwwarehouse.common.tools.ScreenUtils;

import java.util.List;

/**
 * @创建者 chenchao.
 * @创建时间 2017/11/14 11:15
 * @描述 ${TODO}
 */

public class DelayTaskAdapter extends BaseAdapter {

    private Context                      mContext;
    private List<DelayTaskBean.ListBean> mList;
    private GridView                     mGridView;
    private int                          mItemHeight;
    public DelayTaskAdapter(Context context, List list, GridView gridView) {
        mContext = context;
        mList = list;
        mGridView = gridView;
        caculateItemHeight();
    }

    private void caculateItemHeight() {
        int screenHeight = ScreenUtils.getScreenHeight(mContext);
        int screenWidth = ScreenUtils.getScreenWidth(mContext);
        int barHeight = ScreenUtils.getStatusHeight(mContext);
        mItemHeight = (screenHeight - barHeight - ConvertUtils.dip2px(mContext, 120) - ConvertUtils.dip2px(mContext, 35)) / 3;
    }

    @Override
    public int getCount() {
        return mList == null ? 0 : mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        DelayTaskBean.ListBean listBean = mList.get(position);
        DelayTaskAdapter.ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.delay_task_item, null);
            viewHolder = new DelayTaskAdapter.ViewHolder();
            viewHolder.tvCardType = (TextView) convertView.findViewById(R.id.tv_card_type);
            viewHolder.tvOverTime = (TextView) convertView.findViewById(R.id.tv_over_time);
            viewHolder.tvUnit = (TextView) convertView.findViewById(R.id.tv_time_unit);
            viewHolder.tvShopName = (TextView) convertView.findViewById(R.id.tv_shop_name);
            AbsListView.LayoutParams params = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            params.height = mItemHeight;
            convertView.setLayoutParams(params);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (DelayTaskAdapter.ViewHolder) convertView.getTag();
        }

//        if(((MeasureGridview) parent).isOnMeasure){
//            //如果是onMeasure调用的就立即返回
//            return convertView;
//        }

        /* /**
         * delayTime : 445184
         * delayTimeCount : 5
         * delayTimeFormat : 超时5天
         * delayTimeType : 天
         * operationName : 注册审核
         * operationUkid : 42138600000002054
         * ownerId : -1
         * ownerName :
         */

        viewHolder.tvCardType.setText(listBean.getOperationName());
        viewHolder.tvOverTime.setText(listBean.getDelayTimeCount());
        viewHolder.tvUnit.setText(listBean.getDelayTimeType());
        viewHolder.tvShopName.setText(listBean.getOwnerName());
        return convertView;


    }

    private class ViewHolder{
        private TextView tvCardType;
        private TextView tvOverTime;
        private TextView tvUnit;
        private TextView tvShopName;
    }
}
